﻿using System;
using System.IO;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace FSquirrel.Helpers
{
    [ValueConversion(typeof(string), typeof(BitmapImage))]
    public class ExtensionIconConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            MemoryStream iconstream = new MemoryStream();
            IconHelper.IconReader.GetFileIcon(value.ToString(), IconHelper.IconReader.IconSize.Small, false).Save(iconstream);

            BitmapImage image = new BitmapImage();
            image.BeginInit();
            image.StreamSource = iconstream;
            image.EndInit();

            return image;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}